package tankgame;

/**
 * @author: lizhiwen
 * @version: 1.0
 */
public class Shot implements Runnable{
    int x;
    int y;
    int direct = 0;
    int speed = 2;
    boolean isLive = true;

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void setLive(boolean live) {
        isLive = live;
    }


    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            switch (direct){
                //上
                case 0 :
                    y -= speed;
                    break;
                //右
                case 1 :
                    x += speed;
                    break;
                //下
                case 2 :
                    y += speed;
                    break;
                //左
                case 3 :
                    x -= speed;
                    break;
            }
            if (!(x >= 0 && x <= 1000 && y >= 0 && y <= 750) && isLive){
                isLive = false;
                break;
            }
        }
    }
}
